package com.example.controller;

import com.example.dao.ClassesDao;
import com.example.entity.Classes;
import com.example.entity.Student;
import com.example.entity.Teacher;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.jws.WebParam;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("class")
public class ClassesController {
    @Resource
    ClassesDao classesDao;
    @RequestMapping("select")
    public String select(Model model, HttpSession session){
        List<Classes> list=classesDao.selectc();
        model.addAttribute("list",list);
        return "forward:/classList.jsp";
    }
    @RequestMapping("selectT")
    public String selectT(Model model,HttpSession session){
        List<Teacher> headmaster=classesDao.selectTByH();
        model.addAttribute("headmaster",headmaster);
      //  session.setAttribute("headmaster",headmaster);
        List<Teacher> teacher=classesDao.selectTByT();
       model.addAttribute("teacher",teacher);
       // session.setAttribute("teacher",teacher);
        return "forward:/classAdd.jsp";
    }
    @RequestMapping("addClass")
    public String addClass(Classes classes){
       int result=classesDao.addClass(classes);
       if(result!=0){
             return "redirect:/class/select";
       }
        return "error";
    }
    @RequestMapping("del")
    public String del(Integer classid ){
        int result=classesDao.del(classid);
        if(result!=0){
            return "redirect:/class/select";
        }
        return "error";
    }
    @RequestMapping("upd")
    public String upd(Integer classid ,Model model){
        List<Teacher> headmaster=classesDao.selectTByH();
        model.addAttribute("headmaster",headmaster);
        //  session.setAttribute("headmaster",headmaster);
        List<Teacher> teacher=classesDao.selectTByT();
        model.addAttribute("teacher",teacher);
        Map<String,Object> map=classesDao.selectByClassid(classid);
        model.addAttribute("map",map);
        return "forward:/classUpd.jsp";
    }
    @RequestMapping("upd1")
    public String upd1(Classes classes){
       int result=classesDao.upd(classes);
       if (result!=0){
           return "redirect:/class/select";
       }
        return "error";
    }
}
